package com.hinnotek.amoeba.viewmodels


import androidx.lifecycle.viewModelScope
import com.hinnotek.amoeba.base.BaseBean
import com.hinnotek.amoeba.bean.old.ProductManagermentDetailBean
import com.hinnotek.amoeba.repo.ProductRepo
import com.lee.common.base.BaseViewModel
import com.lee.common.network.net.StateLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import okhttp3.RequestBody
import javax.inject.Inject

@HiltViewModel
class ProductViewModel @Inject constructor(val repository: ProductRepo) : BaseViewModel() {


    val productManagermentDetailData = StateLiveData<ProductManagermentDetailBean>()

    fun getProductTypeById(productTypeId: Int): StateLiveData<ProductManagermentDetailBean> {
        viewModelScope.launch {
            repository.getProductTypeById(productTypeId, productManagermentDetailData)
        }
        return productManagermentDetailData
    }


    val baseData = StateLiveData<BaseBean>()


    fun updateProductPrice(productTypeId: Int, productPrice: String) :StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.updateProductPrice(productTypeId,productPrice, baseData)
        }
        return baseData
    }


    fun addProductPicture(imgs: Array<RequestBody?>, productTypeId: Int, createUser: String, deleteIds: String):StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.addProductPicture(imgs,createUser,deleteIds,productTypeId, baseData)
        }
        return baseData
    }

}